package cn.tedu.article1.common.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {
    @ApiModelProperty(value = "状态码", dataType = "int")
    private Integer state;
    @ApiModelProperty(value = "提示信息", dataType = "string")
    private String message;
    @ApiModelProperty(value = "响应数据", dataType = "object")
    private Object data;

    public JsonResult(StatusCode statusCode) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }

    public JsonResult(StatusCode statusCode, Object data) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }

    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }

    public static JsonResult ok(){
        return ok(null);
    }
}
